//该文件是对axios进行配置的
import axios from 'axios'
import {Toast} from 'antd-mobile'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

//请求拦截器
axios.interceptors.request.use((config)=>{
	config.headers.a = 1
	config.timeout = 2000
	config.baseURL = 'http://localhost:5000/api'
	NProgress.start()
	return config
})

//响应拦截器
axios.interceptors.response.use(
	response => {
		NProgress.done()
		return response.data
	},
	error => {
		Toast.fail(error.message)
		NProgress.done()
		return new Promise(()=>{})
	}
)

export default axios